package com.hdl.servlet.user;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import com.hdl.R;
import com.hdl.entity.HdlUser;
import com.hdl.entity.MallAddress;
import com.hdl.exception.CodeException;
import com.hdl.service.MallAddressService;
import com.hdl.service.impl.MallAddressServiceImpl;
import com.hdl.servlet.HttpServletSupport;

/**
 * <pre>
 * - JSON控制器
 * - 商城用户收货地址
 * ClassName : com.hdl.servlet.user.MallAddressServlet
 * @author 湛锋
 * Date : 2020-8-24 14:48:46
 * </pre>
 */
@SuppressWarnings("serial")
@WebServlet("/user/mall-address.let")
public class MallAddressServlet extends HttpServletSupport {
	
	private MallAddressService mallAddressService = new MallAddressServiceImpl();

	public Object add(HdlUser user,MallAddress mallAddress)throws Exception {
		mallAddress.setHdlUserId(user.getHdlUserId());
		if(mallAddress.getMallAddressDefault()==null){
			mallAddress.setMallAddressDefault(0);
		}
		mallAddressService.add(mallAddress);
		
		return R.ok();
	}
	
	public Object update(HdlUser user,MallAddress mallAddress)throws Exception {
		mallAddress.setHdlUserId(user.getHdlUserId());
		if(mallAddress.getMallAddressDefault()==null){
			mallAddress.setMallAddressDefault(0);
		}
		mallAddressService.update(mallAddress);
		return R.ok();
	}
	
	public Object delete(HdlUser user,MallAddress mallAddress)throws Exception {
		mallAddressService.delete(Long.valueOf(mallAddress.getMallAddressId()));
		return R.ok();
	}
}